﻿Imports System.Data.SqlClient

Public Class clsARTICULOS

    Public Sub GUARDA_ARTICULO_GENERALES(ByVal CODIGO As String, ByVal NOMBRE As String, ByVal DESCRIPCION As String, ByVal CLASIF1 As String, ByVal CLASIF2 As String, ByVal CLASIF3 As String, ByVal UNIDAD As String, ByVal CODIGO_SAE As String)
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand("sp_ARTICULOS_INSERTAR", cnConn)
        Command.CommandType = CommandType.StoredProcedure

        Command.Parameters.Add(New SqlParameter("@CODIGO", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO").Value = CODIGO
        Command.Parameters.Add(New SqlParameter("@NOMBRE", SqlDbType.VarChar, 150))
        Command.Parameters("@NOMBRE").Value = NOMBRE
        Command.Parameters.Add(New SqlParameter("@DESCRIPCION", SqlDbType.VarChar, 1000))
        Command.Parameters("@DESCRIPCION").Value = DESCRIPCION
        Command.Parameters.Add(New SqlParameter("@CLASIF1", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF1").Value = CLASIF1
        Command.Parameters.Add(New SqlParameter("@CLASIF2", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF2").Value = CLASIF2
        Command.Parameters.Add(New SqlParameter("@CLASIF3", SqlDbType.VarChar, 100))
        Command.Parameters("@CLASIF3").Value = CLASIF3
        Command.Parameters.Add(New SqlParameter("@UNIDAD", SqlDbType.VarChar, 10))
        Command.Parameters("@UNIDAD").Value = UNIDAD
        Command.Parameters.Add(New SqlParameter("@CODIGO_SAE", SqlDbType.VarChar, 30))
        Command.Parameters("@CODIGO_SAE").Value = CODIGO_SAE
        'Command.Parameters.Add(New SqlParameter("@FECHASTR", SqlDbType.VarChar))
        'Command.Parameters("@FECHASTR").Value = mdatFECHA.ToString("MM/dd/yyyy")
        Dim Lector As SqlDataReader
        Try
            cnConn.Open()

            Lector = Command.ExecuteReader
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try


    End Sub
    Public Sub ACTUALIZA_IMPUESTOS_RETENCIONES(ByVal CODIGO As String, ByVal Impuesto1 As Double, ByVal Impuesto2 As Double, ByVal Impuesto3 As Double, ByVal Retencion1 As Double, ByVal Retencion2 As Double, ByVal Retencion3 As Double)
        Dim sql As String = "UPDATE ARTICULOS_VENTA SET " & _
                            "IMPUESTO1=@IMPUESTO1," & _
                            "IMPUESTO2=@IMPUESTO2," & _
                            "IMPUESTO3=@IMPUESTO3," & _
                            "RETENCION1=@RETENCION1," & _
                            "RETENCION2=@RETENCION2," & _
                            "RETENCION3=@RETENCION3 " & _
                            "WHERE CODIGO=@CODIGO"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CODIGO", CODIGO)
        Command.Parameters.AddWithValue("IMPUESTO1", Impuesto1)
        Command.Parameters.AddWithValue("IMPUESTO2", Impuesto2)
        Command.Parameters.AddWithValue("IMPUESTO3", Impuesto3)
        Command.Parameters.AddWithValue("RETENCION1", Retencion1)
        Command.Parameters.AddWithValue("RETENCION2", Retencion2)
        Command.Parameters.AddWithValue("RETENCION3", Retencion3)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try


    End Sub
    Sub INSERTAR_ARTICULO(ByVal CLAVE As String, ByVal NOMBRE As String, ByVal IDMONEDA As Integer)
        Dim sql As String = "Insert Into ARTICULOS (CODIGO,NOMBRE,ESTATUS,IDMONEDA,CODIGO_SAE) VALUES (" & _
                       "@CODIGO," & _
                       "@NOMBRE," & _
                       "@ESTATUS," & _
                       "@IDMONEDA," & _
                       "@CODIGO_SAE)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CODIGO", CLAVE)
        Command.Parameters.AddWithValue("NOMBRE", NOMBRE)
        Command.Parameters.AddWithValue("ESTATUS", 1)
        Command.Parameters.AddWithValue("IDMONEDA", IDMONEDA)
        Command.Parameters.AddWithValue("CODIGO_sAE", CLAVE)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Sub INSERTAR_ARTICULO_CLIENTE(ByVal IDARTICULO As Integer, ByVal IDSUCURSAL As String, ByVal IDCLIENTE As Integer, ByVal CODIGO As String, ByVal NOMBRE As String, ByVal FACTOR As Double, ByVal PRECIO As Double)
        Dim sql As String = "Insert Into CLIENTES_LISTA_ARTICULOS VALUES (" & _
                       "@IDARTICULO," & _
                       "@IDSUCURSAL," & _
                       "@IDCLIENTE," & _
                       "@CODIGO," & _
                       "@NOMBRE," & _
                       "@FACTOR," & _
                       "@PRECIO)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IDARTICULO", IDARTICULO)
        Command.Parameters.AddWithValue("IDSUCURSAL", IDSUCURSAL)
        Command.Parameters.AddWithValue("IDCLIENTE", IDCLIENTE)
        Command.Parameters.AddWithValue("CODIGO", CODIGO)
        Command.Parameters.AddWithValue("NOMBRE", NOMBRE)
        Command.Parameters.AddWithValue("FACTOR", FACTOR)
        Command.Parameters.AddWithValue("PRECIO", PRECIO)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
    Sub INSERTAR_CUBICACIONES(ByVal IDARTICULO As Integer, ByVal IDSUCURSAL As String, ByVal IDCLIENTE As Integer, ByVal DEPARTAMENTO As String, ByVal FACTOR As Double, ByVal CUBICAJE As Double)
        Dim sql As String = "Insert Into CUBICAJES VALUES (" & _
                       "@IDCLIENTE," & _
                       "@IDSUCURSAL," & _
                       "@IDARTICULO," & _
                       "@DEPARTAMENTO," & _
                       "@FACTOR," & _
                       "@CUBICAJE)"



        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IDCLIENTE", IDCLIENTE)
        Command.Parameters.AddWithValue("IDSUCURSAL", IDSUCURSAL)
        Command.Parameters.AddWithValue("IDARTICULO", IDARTICULO)
        Command.Parameters.AddWithValue("DEPARTAMENTO", DEPARTAMENTO)
        Command.Parameters.AddWithValue("FACTOR", FACTOR)
        Command.Parameters.AddWithValue("CUBICAJE", CUBICAJE)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
            If RowsAffected > 0 Then
                cnConn.Close()
            Else
                If cnConn.State = ConnectionState.Open Then
                    cnConn.Close()
                End If
            End If
        Catch ex As Exception
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End Try
    End Sub
End Class
